<?php
include_once 'Util/functions.php';
if (isset ( $_REQUEST ["act"] )) {
	$action = $_REQUEST ["act"];
} else {
	$action = "";
}

if ($action == "inputdbinfo") {
	
	if (IsNoEmpty ( $_REQUEST ["server"] ) && IsNoEmpty ( $_REQUEST ["user"] )  && IsNoEmpty ( $_REQUEST ["db"] )) {
		session_start ();
		$_SESSION ['DB_SERVER'] = $_REQUEST ["server"];
		$_SESSION ['DB_SERVER_USERNAME'] = $_REQUEST ["user"];
		$_SESSION ['DB_SERVER_PASSWORD'] = empty($_REQUEST ["password"])?"":$_REQUEST ["password"];
		$_SESSION ['DB_DATABASE'] = $_REQUEST ["db"];
	} else {
		include_once "configs/smartmain.php";
		$template->assign ( "errorMessage", "Miss parameters" );
		
		$template->display ( 'index.tpl.html' );
		exit ();
	}

} else if ($action == "usingsessioninfo") {

} else {
	include_once "configs/smartmain.php";
	$template->assign ( "errorMessage", "non action or Unsupport action:" . $action );
	
	$template->display ( 'index.tpl.html' );
	exit ();
}
include_once "configs/smartmain.php";
include_once "configs/Mysql.class.php";


$db = new DB ( );
$query = $db->query ( "show databases" );
$databaseNames = array ();
//echo "start <p>";
for($counter = 0; $row = $db->fetch_array ( $query ); $counter ++) {
	if (! $row) {
		break;
	}
	
	$databaseNames [$counter] = $row ["Database"];
	//echo $counter."=".$row["Database"]."<br>";


}

$db->close ();

//$template->assign ( "Message", "Hello Word!" );
$template->assign ( "dbName", $databaseNames );

$template->display ( 'SelectDB.html' );

?>